var STATE_USER = 3; //默认用户未注册
var STATE_OPENID_ERROR = -1; //openid解密错误
var STATE_USER_REGISTERING = 1; //业主已经注册，正在审核
var STATE_USER_VERIFYED = 2; //业主已经审核通过
var STATE_USER_ISRELATIVES = 4; //已经被业主注册为亲属
var STATE_USER_NONE = 3; //用户还未注册业主

var STATE_ERROR_FACE_YIN_YANG = -1; //阴阳脸。
var STATE_ERROR_FACE_BORDER = -2; //人脸在图像边界处。
var STATE_ERROR_FACE_RESOLUTION = -3; //图像当前分辨率不能识别。
var STATE_ERROR_FACE_ANGLE = -4; //人脸角度偏差太大。
var STATE_ERROR_FACE_NUM = -5; //人脸数量太多或为零（要求只有一个人脸）。
var STATE_ERROR_IMAGE_QUALITY = -6; //图像质量太差。
var STATE_ERROR_OTHER = -7; //其他错误
//   zhsqxcx.dycic.com:8443  192.168.0.157  mp.huaanvision.com:8443
// var BASEURL = 'https://zhsqxcx.dycic.com:8443';
var BASEURL = 'http://192.168.0.122:8081';
var UPLOAD_URL = '/faceAuditinglistController.do?addfaceRole';
var ALLLIST_URL = '/faceAuditinglistController.do?listAll';  
var PHONE_CODE_URL = '/faceAuditinglistController.do?getRancode&personphone='; //获取短信验证码
var PICDETECT_URL = '/faceAuditinglistController.do?returnType';
var USER_LOGIN_URL = '/faceAuditinglistController.do?decodeUserInfo'; 
var USER_VISITOR_URL = '/faceAudivilistController.do?addinterview'; //访客注册
var PHONE_EXIST_URL = "/faceAuditinglistController.do?returnExist"; //判断用户是否存在
var LONG_USER_URL = "/faceRelativelistController.do?addrelation";  //长期人员注册
var VISITOR_PICTURE_URL = "/faceAudivilistController.do?returnPictures"; //访客图片
var GETLONG_HISTORY = "/faceRelativelistController.do?listRelation"; //获取长期人员列表
var DELETE_LONG_USER = "/faceRelativelistController.do?deleteRelation"; //删除长期人员
var DELETE_VISITER = "/faceAudivilistController.do?doDelete"; // 删除访客
var CHECK_LONG_NUM = "/faceRelativelistController.do?count"; //检查亲属人员是否超出
var GET_SHARE_ID = "/faceAuditinglistController.do?getID";
var IS_ID_USED = "/faceAudivilistController.do?TorF";
var FEED_BACK = "/faceFeebackController.do?doadd";
var BANNER = "/facePictureController.do?listAll";  //轮播图
var CHECK_YEZHU = "/faceAuditinglistController.do?existsPer"; //检查小区业主是否被注册
var CHANGE_SHARE_TYPE = "/faceRelativelistController.do?changeShareType";//授权亲属分享
var CHANGE_VISITOR_TYPE = "/faceAudivilistController.do?authorize"; //通过访客申请

var SEND_MODEL_MSG = "https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token=";//发送访客审核通过消息
// 将方法、变量暴露出去
module.exports = {
  BASEURL: BASEURL,
  UPLOAD_URL: UPLOAD_URL,
  ALLLIST_URL: ALLLIST_URL,
  PHONE_CODE_URL: PHONE_CODE_URL,
  PICDETECT_URL: PICDETECT_URL,
  USER_LOGIN_URL: USER_LOGIN_URL,
  USER_VISITOR_URL: USER_VISITOR_URL,
  PHONE_EXIST_URL: PHONE_EXIST_URL,
  LONG_USER_URL: LONG_USER_URL,
  VISITOR_PICTURE_URL: VISITOR_PICTURE_URL,
  GETLONG_HISTORY: GETLONG_HISTORY,
  DELETE_LONG_USER: DELETE_LONG_USER,
  CHECK_LONG_NUM: CHECK_LONG_NUM,
  DELETE_VISITER: DELETE_VISITER,
  GET_SHARE_ID: GET_SHARE_ID,
  IS_ID_USED: IS_ID_USED,
  FEED_BACK: FEED_BACK,
  BANNER: BANNER,

  STATE_USER: STATE_USER,
  STATE_USER_REGISTERING: STATE_USER_REGISTERING,
  STATE_USER_VERIFYED: STATE_USER_VERIFYED,
  STATE_USER_NONE: STATE_USER_NONE,
  STATE_OPENID_ERROR: STATE_OPENID_ERROR,
  STATE_USER_ISRELATIVES: STATE_USER_ISRELATIVES,
  STATE_ERROR_FACE_YIN_YANG: STATE_ERROR_FACE_YIN_YANG,
  STATE_ERROR_FACE_BORDER: STATE_ERROR_FACE_BORDER,
  STATE_ERROR_FACE_RESOLUTION: STATE_ERROR_FACE_RESOLUTION,
  STATE_ERROR_FACE_ANGLE: STATE_ERROR_FACE_ANGLE,
  STATE_ERROR_IMAGE_QUALITY: STATE_ERROR_IMAGE_QUALITY,
  STATE_ERROR_OTHER: STATE_ERROR_OTHER,
  STATE_ERROR_FACE_NUM: STATE_ERROR_FACE_NUM,
  CHECK_YEZHU:CHECK_YEZHU,
  CHANGE_SHARE_TYPE: CHANGE_SHARE_TYPE,
  CHANGE_VISITOR_TYPE: CHANGE_VISITOR_TYPE,
  SEND_MODEL_MSG: SEND_MODEL_MSG,
  idCard: idCard
}


function idCard(cardNum) {
  /*
    该方法由网友提供;
    对身份证进行严格验证;
  */

  var Wi = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2, 1];// 加权因子;
  var ValideCode = [1, 0, 10, 9, 8, 7, 6, 5, 4, 3, 2];// 身份证验证位值，10代表X;

  if (cardNum.length == 15) {
    return isValidityBrithBy15IdCard(cardNum);
  } else if (cardNum.length == 18) {
    var a_idCard = cardNum.split("");// 得到身份证数组   
    if (isValidityBrithBy18IdCard(cardNum) && isTrueValidateCodeBy18IdCard(a_idCard)) {
      return true;
    }
    return false;
  }
  return false;

  function isTrueValidateCodeBy18IdCard(a_idCard) {
    var sum = 0; // 声明加权求和变量   
    if (a_idCard[17].toLowerCase() == 'x') {
      a_idCard[17] = 10;// 将最后位为x的验证码替换为10方便后续操作   
    }
    for (var i = 0; i < 17; i++) {
      sum += Wi[i] * a_idCard[i];// 加权求和   
    }
    let valCodePosition = sum % 11;// 得到验证码所位置   
    console.log(a_idCard[17])
    if (a_idCard[17] == ValideCode[valCodePosition]) {
      console.log("isTrueValidateCodeBy18IdCard通过")
      return true;
    }
    console.log("isTrueValidateCodeBy18IdCard没有通过")
    return false;
  }

  function isValidityBrithBy18IdCard(idCard18) {
    var year = idCard18.substring(6, 10);
    var month = idCard18.substring(10, 12);
    var day = idCard18.substring(12, 14);
    var temp_date = new Date(year, parseFloat(month) - 1, parseFloat(day));
    // 这里用getFullYear()获取年份，避免千年虫问题   
    if (temp_date.getFullYear() != parseFloat(year) || temp_date.getMonth() != parseFloat(month) - 1 || temp_date.getDate() != parseFloat(day)) {
      console.log("isTrueValidateCodeBy18IdCard没有通过")
      return false;
    }
    return true;
  }

  function isValidityBrithBy15IdCard(idCard15) {
    var year = idCard15.substring(6, 8);
    var month = idCard15.substring(8, 10);
    var day = idCard15.substring(10, 12);
    var temp_date = new Date(year, parseFloat(month) - 1, parseFloat(day));
    // 对于老身份证中的你年龄则不需考虑千年虫问题而使用getYear()方法   
    if (temp_date.getYear() != parseFloat(year) || temp_date.getMonth() != parseFloat(month) - 1 || temp_date.getDate() != parseFloat(day)) {
      return false;
    }
    return true;
  }

}
